import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_yyt/models/care_report_entity.dart';
import 'package:ls_work/a_yyt/models/handover_entity.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';
// import 'package:ls_work/util/toast.dart';
import 'dart:convert' as convert;

class HomeHandoverCell extends StatelessWidget {
  final HandoverInfo? info;
  final VoidCallback? callBack;
  HomeHandoverCell({Key? key, this.info, this.callBack});
  @override
  Widget build(BuildContext context) {
    String successionTime =
        info?.successionTime ??'';
    Map<String, dynamic>? beanInfoStr =
        info?.detail != null ? convert.jsonDecode(info!.detail!) : null;

    BeanInfo? beanInfo =
        beanInfoStr != null ? BeanInfo.fromJson(beanInfoStr) : null;
    String sex = beanInfo != null ? (beanInfo.sex == 0 ? '男' : '女') : '';
    String nurseLevelName = beanInfo != null
        ? (beanInfo.nurseLevelName != null
            ? '护理{${beanInfo.nurseLevelName}'
            : '')
        : '';
    return Container(
      color: Colours.bg_color,
      width: ScreenUtil.getScreenW(context),
      padding: EdgeInsets.fromLTRB(15, 15, 15, 0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(10, 15, 10, 20),
            width: ScreenUtil.getScreenW(context),
            margin: EdgeInsets.fromLTRB(12, 0, 12, 0),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(5),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    _item('交班', '${info?.shifter}', '${info?.shiftTime}'),
                    _item('接班', '${info?.successor}', '$successionTime'),
                    ActionChip(
                      //交接班状态 0-待接班， 1-接班完成
                      label: Text(info?.status == 0 ? '接班' : '完成',
                          style: TextStyle(color: Colors.white)),
                      backgroundColor: info?.status == 0
                          ? Colours.app_main
                          : Colours.bg_color,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(5.0),
                      ),
                      onPressed: () {
                        if (info?.status == 0) {
                          if(callBack!=null){
                            callBack!();
                          }
                        }
                      },
                    ),
                  ],
                ),
                Divider(),
                (beanInfo != null && beanInfo.nurserRecordIsbars != null &&
                        beanInfo.nurserRecordIsbars!.length > 0)
                    ? _handoverItem()
                    : Text(
                        '${beanInfo != null ? beanInfo.elderName : ''}  $sex  ${beanInfo != null ? beanInfo.age : ''}  ${beanInfo != null ? beanInfo.bedNo : ''}  $nurseLevelName',
                        style: TextStyles.textDark14,
                      ),
              ],
            ),
          )
        ],
      ),
    );
  }

  ///交接项
  Widget _handoverItem() {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text('data'),
        ],
      ),
    );
  }

  Widget _item(String title, String content, String time) {
    return Column(
      children: <Widget>[
        Text(
          title,
          style: TextStyles.textBoldDark16,
        ),
        SizedBox(
          height: 5,
        ),
        Text(
          content,
          style: TextStyles.textGray12,
        ),
        SizedBox(
          height: 5,
        ),
        Text(
          time,
          style: TextStyles.textGray12,
        )
      ],
    );
  }
}
